<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title>销货单记录-库存管理</title>
</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">

<div class="layui-body" style="padding:15px;top: 0px;">

    <!-- start sp-wrapper -->
    <link rel="stylesheet" href="/sb/stock.css"/>
    <div class="sp-wrapper">
        <h2 class="sp-title"><span>销货单记录</span></h2>
        <div class="sp-tool">
            <span class="fl">
                <form action="/stock/purchase_list" method="get">
                <b><input type="text" name="billNo" th:value="${billNo}" placeholder="输入单据编号查询"></b>
                <b>单据日期：<input type="text" name="startDate" id="startDate" th:value="${startDate}" class="date"
                               autocomplete="off"> -
                    <input type="text" th:value="${endDate}" name="endDate" id="endDate" class="date"
                           autocomplete="off">
                    <input type="submit" class="button" value="查询"></b>
                </form>
            </span>

            <span class="fr"><a href="/stock/sales_order_add" class="add">新增</a><i>导出</i></span>
        </div>
        <div class="sp-table">
            <form action="#" id="sp-form">
                <table>
                    <thead>
                    <tr>
                        <th>单据日期</th>
                        <th>单据编号</th>
                        <th>供应商</th>
                        <th>购货金额</th>
                        <th>优惠后金额</th>
                        <th>已付款</th>
                        <th>付款状态</th>
                        <th>数量</th>
                        <th>制单人</th>
                        <th>审核人</th>
                        <th>备注</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="sp-data">
                    <tr th:each="item:${list}">
                        <td th:text="${item.billDate}">2019-03-15</td>
                        <td th:text="${item.billNo}">CG201903121700193</td>
                        <td th:text="${item.contactName}">华衣</td>
                        <td th:text="${#numbers.formatDecimal(item.totalAmount, 0, 2)}">1000.00</td>
                        <td th:text="${#numbers.formatDecimal(item.amount, 0, 2)}">900.00</td>
                        <td th:text="${#numbers.formatDecimal(item.rpAmount, 0, 2)}">500.00</td>
                        <td th:switch="${item.rpAmount}">
                            <b th:case="0">未付款</b>
                            <b th:case="item.amount">已付款</b>
                            <b th:case="*">部分付款</b>
                        </td>
                        <td th:text="${item.totalQuantity}">500</td>
                        <td th:text="${item.userName}">华衣</td>
                        <td th:text="${item.checkName}">华衣</td>
                        <td th:text="${item.description}">收到货请检查</td>
                        <td>
                            <!--<a href="ghd.html">修改</a>-->
                            <i class="delete" th:attr="data-id=${item.id}">删除</i>
                        </td>
                    </tr>

                    </tbody>
                </table>
            </form>
        </div>
    </div>

    <script type="text/javascript" src="/sb/jquery.min.js"></script>
    <script type="text/javascript" src="/sb/Tips.min.js"></script>
    <script type="text/javascript">
        $(function () {
            // 删除
            $('.delete').click(function () {
                var obj = $(this).parent().parent();
                var id = $(this).attr('data-id');
                Tips.confirm({
                    title: '删除记录',
                    content: '您确定要删除该购货记录吗？',
                    define: function () {

                        // ajax处理invoice_delete
                        $.ajax({
                            url: "/stock_api/invoice_delete",
                            type: "POST",
                            dataType: "json",
                            contentType: "application/json",
                            data: JSON.stringify({id: id}),
                            success: function (res) {
                                // alert(res.data.length);
                                if (res.code == 0) {
                                    Tips.alert('删除成功', function () {
                                        // location.reload(true);
                                        $(obj).remove();
                                    });

                                }
                                // alert(JSON.stringify(res));
                            }
                        });

                        // .. id
                        // Tips.alert('删除成功', function () {
                        //     location.reload(true);
                        // });
                    }
                });
            });
        });
    </script>
    <!-- end sp-wrapper -->
    <script>
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#startDate' //指定元素
            });
            laydate.render({
                elem: '#endDate' //指定元素
            });

            // laydate.render({
            //     elem: '#startDate'
            //     ,range: true
            // });
        });
    </script>
</div>
</body>
<html>
